package com.lyz.innerclass;

/**
 * @ClassName Test2
 * @Description 匿名内部类的使用形式
 * @Author 2214361854
 * @Date 2022/2/19 17:24
 * @Version 1.0
 */
public class Test2 {
    public static void main(String[] args) {

        Swimming sw1 = new Student();
        gp(sw1);

        //匿名类1
        Swimming sw2 = new Swimming(){
            @Override
            public void swim() {
                System.out.println("老师泳游");
            }
        };
        gp(sw2);
        //匿名类入参形式写法
        gp(new Swimming(){
            @Override
            public void swim() {
                System.out.println("运动员泳游");
            }
        });
        //lambda
        gp(() -> System.out.println("运动员泳游"));


    }
    public static void gp(Swimming s){
        System.out.println("开始");
        s.swim();
        System.out.println("结束");
    }
}
class Student implements Swimming{

    @Override
    public void swim() {
        System.out.println("学生泳游");
    }
}
interface Swimming{
    void swim();
}